﻿using PMS.XCMG.Util;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 系统用户
    /// </summary>
    public partial class Sys_User : BusEntity
    {
        /// <summary>
        /// 工号、编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public string Status { get; set; }

        /// <summary>
        /// 所属组织
        /// </summary>
        public string OrgId { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        public string Sex { get; set; }

        /// <summary>
        /// 默认仓库Id
        /// </summary>
        public string CompanyId { get; set; }
    }
    public partial class Sys_User : BusEntity
    {
        /// <summary>
        /// 所属组织
        /// </summary>
        public Sys_Org Org { get; set; }
    }
    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class Sys_UserTypeConfig : BusEntityTypeConfig<Sys_User>, IEntityTypeConfiguration<Sys_User>
    {
        public override void Configure(EntityTypeBuilder<Sys_User> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Org).WithMany().HasForeignKey(p => p.OrgId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefMiddleColLen).IsRequired();
            builder.Property(p => p.UserName).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Password).HasMaxLength(EntityDefinition.DefMiddleColLen).IsRequired();
            builder.Property(p => p.Status).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.OrgId).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.Sex).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.CompanyId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("系统用户");
            builder.Property(p => p.Code).HasComment("编码");
            builder.Property(p => p.Name).HasComment("名称");
            builder.Property(p => p.UserName).HasComment("用户名");
            builder.Property(p => p.Password).HasComment("密码");
            builder.Property(p => p.Status).HasComment("状态");
            builder.Property(p => p.OrgId).HasComment("所属组织");
            builder.Property(p => p.Sex).HasComment("性别");
            builder.Property(p => p.CompanyId).HasComment("公司Id");
            #endregion

            #region 种子数据
            builder.HasData(new Sys_User { Id = "1", Code = "SystemManager", Name = "系统管理员", UserName = "admin", Password = "e10adc3949ba59abbe56e057f20f883e", Status = "Enable", OrgId = "1", Sex = "Boy", CompanyId = EntityDefinition.DefSysCode, CreateUserId = "1", ModifyUserId = "1" });
            #endregion
        }
    }
}
